package com.example.servlet;

import com.example.dao.NovelDao;
import com.example.domain.Novel;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/AdminNovelUpdateServlet")
public class AdminNovelUpdateServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        request.setCharacterEncoding("utf-8");
        int novel_id=Integer.parseInt(request.getParameter("novel_id"));
        String title=request.getParameter("title");
        String author=request.getParameter("author");
        String description=request.getParameter("description");
        String cover_image_url=request.getParameter("cover_image_url");
        String category=request.getParameter("category");
        String status=request.getParameter("statu_s");
        String update_time=request.getParameter("update_time");
        int click_count=Integer.parseInt(request.getParameter("click_count"));
        Novel novel=new Novel(novel_id,title,author,description,cover_image_url,category,status,update_time,click_count);
        NovelDao novelDao=new NovelDao();
        int affectedRow = novelDao.updateNovel(novel);
        novel=novelDao.getNovelById(novel_id);
        if(affectedRow>0){
            request.setAttribute("msg","修改成功");
        }else{
            request.setAttribute("msg","修改失败");
        }
        request.setAttribute("novel",novel);
        request.getRequestDispatcher("admin_NovelUpdate.jsp").forward(request,response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        this.doGet(request,response);
    }
}
